<?php
session_start();
define('FLYCMS' , '0.01'); 
include('functions.php');
include_once('./config.php'); 
include_once('./others/classes/mysql.class.php'); 
$cms = new cms (); 
$sql = new mysql (); 
$cms -> check_login();  // Проверяка админ прав
$sql -> connect ( $config['dbuser'], $config['dbpass'],   $config['dbname'] ) ; // Подсоеденяемся к MySQL

if ( isset($_REQUEST['setstatus']) & isset($_REQUEST['newsid']) ) {
	if ($_REQUEST['setstatus'] == 'true' || $_REQUEST['setstatus'] == "1" ) {
		$temp_query = "UPDATE `".$config['dbprefix']."news` SET status = '1' WHERE `id` = ".$_REQUEST['newsid']." LIMIT 1"; 
	//	print $temp_query; 
		$sql -> query (  $temp_query) ; 
	} else if ( $_REQUEST['setstatus']=='false' || $_REQUEST['setstatus'] =='0') {
		$temp_query = "UPDATE `".$config['dbprefix']."news` SET status = '0' WHERE `id` = ".$_REQUEST['newsid']." LIMIT 1" ; 
	//	print $temp_query; 
		$sql -> query ($temp_query) ; 
	} else {
		print 'ERRor'; 
	}
} 
?>
<html><head>
<title>FLYCMS - панель администратора</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" media="all" href="admin_style.css" /><?/*
<script src="jscripts/prototype.js" type="text/javascript"></script>
<script src="jscripts/scriptaculous.js" type="text/javascript"></script>*/ ?> 
</head> <body>
<table width="100%"  >
  <tr>
  <td>
	<div class="error"> <?php print @$error ?> </div> 
 	<?php 
 		if ($_REQUEST['edit'] && $_REQUEST['news'] ){}
 		else if ( $_REQUEST['add']  ) { 
 		 
 
print "
   <fieldset>
   	<legend>Добавить новость</legend>"; 
 
  			if ($cms -> addnews_check() == true )
  				{
  					if (isset($temp_addnews_error)){ print $temp_addnews_error ; } $cms -> addnews_form();   
  				} else {	print "Добавьте новую новость!";$cms -> addnews_form();    }  	
   			
   			 
			
	
print "</fieldset>";
 					// } //
 			
 		} 
 		else   {  
 	 ?>
  	<fieldset>
    		<legend>Новости</legend>
    		<table class="newses"  cellpadding="0" cellspacing="0" >
      			<thead>
      				<tr class="title">
	  				<td>ID</td>
	  				<td>Заголовок</td>
	  				<td>Дата</td>
	  				<td>Статус</td>
				</tr> 
				<?php
   	$temp_sql = $sql ->  query("SELECT * FROM ".$config['dbprefix']."news");
	// Если нету результатов 
 	    		  while($temp_data =  $sql -> get_row($temp_sql) )  			{ 
 				 	 print "<tr><td>".$temp_data['id']."</td> <td>".$temp_data['title']."</td><td>".$temp_data['date']."</td> <td>";
 				 	 if ($temp_data['status']==1) {
 				 	 	print "[ <a href='?setstatus=0&newsid=".$temp_data['id']."'>+</a> ]"; 
 				 	 } else {
 				 	 	print "[ <a href='?setstatus=1&newsid=".$temp_data['id']."'>-</a> ]"; 
 				 	 }
 				 		print "</td> <tr>  ";
 				  
				} 
 	//	}  else  {  
		//	  print "<tr><td>Нету новостей <a href='./?add=1&news=1'>Добавить </a> </td> </tr>   "; 
 	//	}
?> 
      			</thead>
     	    </table>	
   </fieldset>
 <?php 
 } // 
 ?>
  </td>
  <td width="150px">
  	<div class='anav'>
    		<a href='./?'>Главная </a>
    		<a href='./?add=true'>Добавить </a>
  	</div> 
  </td>
  </tr>
</table>
</body>
</html>
<?php 

	$sql -> close(); 
 

?>
